package com.echo.code.spring.springbootdemo.spel;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource;

import java.io.IOException;

/**
 * Description
 *
 * @author baiyp
 * @version 1.0.0
 * @date 2019/04/27
 */
@Configuration
@PropertySource(value = "classpath:application.properties")
@ComponentScan(value = "com.echo.code.spring.springbootdemo.spel")
@Slf4j
@Setter
@Getter
@ToString
@EnableConfigurationProperties(AutoConfig.class)
public class CustomConfig {

  @Value("I Love You!")
  private String confession;

  @Value("#{systemProperties['os.name']}")
  private String osName;

  @Value("#{ T(java.lang.Math).random() * 100.0 }")
  private double randomNumber;

  @Value("classpath:wallhaven-764609.png")
  private Resource wallImage;

  @Value("${author.email}")
  private String authorEmail;

  @Autowired
  private Environment environment;

  public void getWallImageInfo() throws IOException {
    log.info("fileName is: " + wallImage.getFile().getName());
  }
}
